package com.wws.family.utils

import android.animation.ObjectAnimator
import android.content.Context
import android.view.animation.LinearInterpolator
import android.widget.ImageView
import com.wws.family.R

/**
 *@Description: 公共工具类
 *@Date: 2024/9/19 23:15
 *@Author: WangWeiShuo
 */
object PublicUtils {

    data class MedicineType(val icon: Int,val name: String)

    fun getMedicineTypeList(): MutableList<MedicineType>{
        return mutableListOf(MedicineType(R.drawable.icon_yaowan,"药片、胶囊")
        ,MedicineType(R.drawable.icon_koufuye,"口服液、糖浆")
        ,MedicineType(R.drawable.icon_chongji,"颗粒、冲剂"))
    }

    /**
     * 读取assets文件
     * @param context Context
     * @param fileName String
     * @return String
     */
    fun getAssetsFile(context: Context,fileName: String): String{
        context.assets.open(fileName).bufferedReader().use {
            return it.readText()
        }
    }

    fun setArrowDownUp(view: ImageView, isDown: Boolean){
        if(isDown){
            val rotateAnimator = ObjectAnimator.ofFloat(view, "rotation", 180f, 0f)
            rotateAnimator.duration = 500
            rotateAnimator.interpolator = LinearInterpolator()
            rotateAnimator.repeatCount = 0
            rotateAnimator.start()
        }else{
            val rotateAnimator = ObjectAnimator.ofFloat(view, "rotation", 0f, 180f)
            rotateAnimator.duration = 500
            rotateAnimator.interpolator = LinearInterpolator()
            rotateAnimator.repeatCount = 0
            rotateAnimator.start()
        }
    }
}